package com.xunyin.utils;


import java.io.Serializable;

/**
 * 统一返回结果类
 */
public class BaseResult implements Serializable {

    /**
     * 状态码：200成功，其他为失败
     * <p>
     * 业务代码
     * 五位数
     * 为10000
     * 可以自定义返回内容，如果未定义则在配置文件中查找
     */
    public String code;

    // 成功为success，其他为失败原因
    public String message;

    // 数据结果集
    public Object data;

    public BaseResult() {
    }

    public BaseResult(String code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static BaseResult success() {
        BaseResult baseResult = new BaseResult();
        baseResult.setCode("200");
        baseResult.setMessage("操作成功");
        return baseResult;
    }

    public static BaseResult success(Object object) {
        BaseResult baseResult = new BaseResult();
        baseResult.setCode("200");
        baseResult.setMessage("操作成功");
        baseResult.setData(object);
        return baseResult;
    }

    public static BaseResult fail() {
        BaseResult baseResult = new BaseResult();
        baseResult.setCode("500");
        baseResult.setMessage("操作失败");
        return baseResult;
    }

    public static BaseResult fail(String code, String message) {
        BaseResult baseResult = new BaseResult();
        baseResult.setCode(code);
        baseResult.setMessage(message);
        return baseResult;
    }
}
